#!/bin/bash

if [ -n "$1" ]; then
    data_date=$1
else
  data_date=`date -d '-1 days' +%F`
fi

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_vivo_log \
--username root \
--password 123456 \
--as-textfile \
--fields-terminated-by '\001' \
--query 'SELECT app_id,app_name,app_category,app_subcategory,developer,publish_date,is_official,is_preinstalled,min_os_version,price,avg_rating,download_count,update_frequency,last_update_date,description,update_time FROM vivo_app_info WHERE $CONDITIONS AND 1=1' \
--target-dir "hdfs://node101:8020/warehouse/vivo_app_warehouse/vivo_app_info/${data_date}" \
--delete-target-dir \
--null-non-string '\\N' \
--null-string '\\N' \
--num-mappers 1

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_vivo_log \
--username root \
--password 123456 \
--as-textfile \
--fields-terminated-by '\001' \
--query 'SELECT device_id,user_id,device_type,device_model,manufacture_date,purchase_date,screen_size,resolution,memory_size,storage_size,os_type,os_version,network_type,is_rooted,update_time FROM vivo_device_info WHERE $CONDITIONS AND 1=1' \
--target-dir "hdfs://node101:8020/warehouse/vivo_app_warehouse/vivo_device_info/${data_date}" \
--delete-target-dir \
--null-non-string '\\N' \
--null-string '\\N' \
--num-mappers 1

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_vivo_log \
--username root \
--password 123456 \
--as-textfile \
--fields-terminated-by '\001' \
--query 'SELECT location_id,country,province,city,district,longitude,latitude,timezone,gdp,population,is_first_tier_city,is_tourist_city,development_level,update_time FROM vivo_location_info WHERE $CONDITIONS AND 1=1' \
--target-dir "hdfs://node101:8020/warehouse/vivo_app_warehouse/vivo_location_info/${data_date}" \
--delete-target-dir \
--null-non-string '\\N' \
--null-string '\\N' \
--num-mappers 1

sqoop import \
--connect jdbc:mysql://node101:3306/jtp_vivo_log \
--username root \
--password 123456 \
--as-textfile \
--fields-terminated-by '\001' \
--query 'SELECT user_id,register_date,age,gender,vip_level,vip_expire_date,phone_brand,phone_model,os_version,first_login_date,last_login_date,province,city,district,is_active,user_tag,update_time FROM vivo_user_info WHERE $CONDITIONS AND 1=1' \
--target-dir "hdfs://node101:8020/warehouse/vivo_app_warehouse/vivo_user_info/${data_date}" \
--delete-target-dir \
--null-non-string '\\N' \
--null-string '\\N' \
--num-mappers 1